package com.ruoyi.vehicles.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.utils.ImageUtil;
import com.ruoyi.vehicles.form.AddRecordsForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.vehicles.domain.AMaintenanceRecords;
import com.ruoyi.vehicles.service.IAMaintenanceRecordsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 维护记录Controller
 * 
 * @author ruoyi
 * @date 2025-04-07
 */
@RestController
@RequestMapping("/records")
public class AMaintenanceRecordsController extends BaseController
{
    @Autowired
    private IAMaintenanceRecordsService aMaintenanceRecordsService;

    /**
     * 查询维护记录列表
     */
    @RequiresPermissions("vehicles:records:list")
    @GetMapping("/list")
    public TableDataInfo list(AMaintenanceRecords aMaintenanceRecords)
    {
        startPage();
        List<AMaintenanceRecords> list = aMaintenanceRecordsService.selectAMaintenanceRecordsList(aMaintenanceRecords);
        return getDataTable(list);
    }

    /**
     * 导出维护记录列表
     */
    @RequiresPermissions("vehicles:records:export")
    @Log(title = "维护记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AMaintenanceRecords aMaintenanceRecords)
    {
        List<AMaintenanceRecords> list = aMaintenanceRecordsService.selectAMaintenanceRecordsList(aMaintenanceRecords);
        ExcelUtil<AMaintenanceRecords> util = new ExcelUtil<AMaintenanceRecords>(AMaintenanceRecords.class);
        util.exportExcel(response, list, "维护记录数据");
    }

    /**
     * 获取维护记录详细信息
     */
    @RequiresPermissions("vehicles:records:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(aMaintenanceRecordsService.selectAMaintenanceRecordsById(id));
    }

    /**
     * 新增维护记录
     */
    @RequiresPermissions("vehicles:records:add")
    @Log(title = "维护记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(AddRecordsForm aMaintenanceRecords)
    {
        return toAjax(aMaintenanceRecordsService.insertAMaintenanceRecords(aMaintenanceRecords));
    }

    /**
     * 修改维护记录
     */
    @RequiresPermissions("vehicles:records:edit")
    @Log(title = "维护记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AMaintenanceRecords aMaintenanceRecords)
    {
        return toAjax(aMaintenanceRecordsService.updateAMaintenanceRecords(aMaintenanceRecords));
    }

    /**
     * 删除维护记录
     */
    @RequiresPermissions("vehicles:records:remove")
    @Log(title = "维护记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aMaintenanceRecordsService.deleteAMaintenanceRecordsByIds(ids));
    }
}
